use std::fs::File;

// fn passive_panic() {
//     let v = vec![1, 2, 3];

//     v[99];
// }

// fn active_panic() {
//     panic!("crash and burn");
// }

// fn test_panic() {
//     passive_panic();
//     active_panic();
// }

fn test_result() {
    // let f = File::open("hello.txt").unwrap();
    // let f = File::open("hello.txt").expect("Failed to open hello.txt");
    let f = File::open("hello.txt");
    let _f = match f {
        Ok(file) => file,
        Err(error) => match error.kind() {
            std::io::ErrorKind::NotFound => match File::create("hello.txt") {
                Ok(fc) => fc,
                Err(e) => panic!("Problem creating the file: {:?}", e),
            },
            other_error => panic!("Problem opening the file: {:?}", other_error),
        }
    };
}

fn main() {
    // test_panic();
    test_result();
}
